package Teacher_Test.JDBC_test.dao.impl;

import Teacher_Test.JDBC_test.dao.UserDao;
import day01_IO_JDBC.demo_JDBC_emp_pro.DBUtil.DBPoollUtils;
import day01_IO_JDBC.demo_JDBC_users.Entity.Users;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public boolean deleteById(int id) {
        Connection connection= DBPoollUtils.getConnection();
        if (connection != null){
            try {
                String sql = " delete from users where id = ? ";
                PreparedStatement preparedStatement = connection.prepareStatement(sql);
                preparedStatement.setInt(1,id);
                int num= preparedStatement.executeUpdate();
                if (num>0){
                    System.out.println("删除成功");
                    return true;
                }
                else{
                    System.out.println("删除失败");
                    return false;
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

}
